﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

using PublicDomain.Data.Csv;

namespace PublicDomain.UnitTest.Data.Csv
{
    [TestClass]
    public class CsvConnectionStringBuilderTest
    {
        public TestContext TestContext { get; set; }

        [TestMethod]
        [Description("Tests constructor CsvConnectionStringBuilder(string connectionString).")]
        public void CsvConnectionStringBuilderConstructorTest()
        {
            const string connectionString = "Database=C:\\Temp\\User Abc;Delimiter=,;HeaderRowsCount=1;SchemataFilePath=C:\\Raw Data\\CsvDataFormat.xml;ParsingOptions=EscapedEmptyAsZeroLengthString, AllowLessColumnsInOneRecord";
            var target = new CsvConnectionStringBuilder(connectionString);

            Assert.AreEqual("database=\"C:\\Temp\\User Abc\";delimiter=,;headerrowscount=1;schematafilepath=\"C:\\Raw Data\\CsvDataFormat.xml\";parsingoptions=\"EscapedEmptyAsZeroLengthString, AllowLessColumnsInOneRecord\"", target.ConnectionString);
            Assert.AreEqual("C:\\Temp\\User Abc", target.Database);
            Assert.AreEqual(new char?(','), target.Delimiter);
            Assert.AreEqual(new int?(1), target.HeaderRowsCount);
            Assert.AreEqual("C:\\Raw Data\\CsvDataFormat.xml", target.SchemataFilePath);
            Assert.AreEqual(CsvParsingOptions.AllowLessColumnsInOneRecord | CsvParsingOptions.EscapedEmptyAsZeroLengthString, target.ParsingOptions);

            var target2 = new CsvConnectionStringBuilder();
            target2.Database = target.Database;
            target2.Delimiter = target.Delimiter;
            target2.HeaderRowsCount = target.HeaderRowsCount;
            target2.SchemataFilePath = target.SchemataFilePath;
            target2.ParsingOptions = target.ParsingOptions;

            Assert.AreEqual(target.ConnectionString, target2.ConnectionString);
        }

        [TestMethod]
        [Description("Tests default constructor CsvConnectionStringBuilder().")]
        public void CsvConnectionStringBuilderDefaultConstructorTest()
        {
            var target = new CsvConnectionStringBuilder();

            Assert.IsNull(target.Database);
            Assert.IsNull(target.Delimiter);
            Assert.IsNull(target.HeaderRowsCount);
            Assert.IsNull(target.SchemataFilePath);
            Assert.AreEqual(CsvParsingOptions.None, target.ParsingOptions);
        }
    }
}
